package com.fun;

import java.io.IOException;
import java.util.Map;

import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;


public class HTClient {
	
	public static String Send(Map<String,Object> map) throws IOException {
		OkHttpClient client = new OkHttpClient();
        StringBuilder sb = new StringBuilder(2000);
        sb.append(map.get("url"));
        sb.append("?1=1");
        for(String key: map.keySet()) {
        	if(key.equals("url"))continue;
        	sb.append("&").append(key).append("=").append(map.get(key));
        }
        Request request = new Request.Builder()
                .url(sb.toString())
                .build();
     
        Response response = client.newCall(request).execute();
        if (!response.isSuccessful()) {
            throw new IOException("服务器端错误: " + response);
        }
     
        Headers responseHeaders = response.headers();
        for (int i = 0; i < responseHeaders.size(); i++) {
            //System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
        }
        String dd = response.body().string();
        return dd;
	}
	
}
